package com.cn.design.factory.ioc;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author xuhui
 * @Description:
 * @date 2022-06-30 16:59
 **/
public class IocClient {
    @SneakyThrows
    public static void main(String[] args) {
        Properties pro=Init.getProperties();
        Phone phone = PhoneFactory.getInstance(pro.getProperty("iphone"));

    }


}

class Init {
    public static Properties getProperties() throws IOException {
        Properties pro=new Properties();
        File f = new File("phone.properties");
        if(f.exists()){
            pro.load(new FileInputStream(f));
        }else{
            pro.setProperty("iphone", "com.design.factory.ioc.IPhone");
            pro.setProperty("miPhone", "com.design.factory.ioc.MiPhone");
            pro.store(new FileOutputStream(f), "PHONE CLASS");
        }
        return pro;
    }
}